package cn.arnold.offer.bytedance.ceshi;

import java.util.*;

/**
 * @author Arnold-Xiang
 * @Info
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int key = sc.nextInt();
            int value = sc.nextInt();
            if (map.containsKey(key)) {
                int tmpValue = map.get(key) + value;
                map.put(key, tmpValue);
            } else {
                map.put(key, value);
            }
        }
        List<Map.Entry<Integer, Integer>> list = new ArrayList<>(map.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<Integer, Integer>>() {
            @Override
            public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
                return o2.getValue() - o1.getValue();
            }
        });
        Set<Integer> keys = map.keySet();
        int count = 0;
        for (Integer key : keys) {
            count++;
            if (count < m){
                System.out.println(key);
            }

        }


    }
}
